package com.qf.wangqing.sportsnews.fragment;


import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.qf.wangqing.sportsnews.R;
import com.qf.wangqing.sportsnews.activity.CommunityActivity;
import com.qf.wangqing.sportsnews.databinding.FragmentSlidingBinding;


/**
 * A simple {@link Fragment} subclass.
 */
public class SlidingFragment extends Fragment implements RadioGroup.OnCheckedChangeListener {
    private FragmentSlidingBinding binding;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

//       binding=DataBindingUtil.inflate(LayoutInflater.from(getContext()),R.layout.fragment_sliding,container,false);
        binding=DataBindingUtil.inflate(LayoutInflater.from(getContext()),R.layout.fragment_sliding,container,false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding.groupSliding.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        RadioButton button= (RadioButton) radioGroup.getChildAt(i);
        switch (i) {
            case R.id.search_slidingfragment:
                Toast.makeText(getContext(),"search",Toast.LENGTH_SHORT).show();
                break;
            case R.id.community_slidingfragment:
                Intent intent = new Intent(getContext(), CommunityActivity.class);
                getContext().startActivity(intent);
                break;
        }
    }
}
